package com.pick.admin.config;

import cn.dev33.satoken.stp.StpInterface;
import com.pick.admin.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * Sa-Token权限验证接口实现
 * 用于Sa-Token框架获取用户的权限和角色信息
 */
@Component
public class StpInterfaceImpl implements StpInterface {

    @Autowired
    private SysUserService userService;

    /**
     * 返回一个账号所拥有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        Long userId = Long.valueOf(loginId.toString());
        return userService.getUserPermissionCodes(userId);
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        Long userId = Long.valueOf(loginId.toString());
        return userService.getUserRoleCodes(userId);
    }
}